package it.unipd.dei.project.iandroid;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MatchAdapter extends ArrayAdapter<Match> {

	private ArrayList<Match> items;
	private Context context;

	public MatchAdapter(Context context, int textViewResourceId, ArrayList<Match> items) {
		super(context, textViewResourceId, items);
		this.context = context;
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.match_adapter_layout, null);
		}

		Match c = this.items.get(position);
		if (c != null) {
			TextView homeTeam = (TextView) v.findViewById(R.id.homeTeam);
			homeTeam.setText(c.getHomeTeam());
			TextView foreinTeam = (TextView) v.findViewById(R.id.foreinTeam);
			foreinTeam.setText(c.getForeinTeam());
			TextView hour = (TextView) v.findViewById(R.id.hour);
			hour.setText(c.getHour());
			TextView phase = (TextView) v.findViewById(R.id.phase);
			phase.setText(c.getPhase());
			TextView court = (TextView) v.findViewById(R.id.court);
			court.setText(c.getCourt());
			ImageView picImageView = (ImageView) v.findViewById(R.id.icon);
			picImageView.setImageBitmap(c.getIcon());
		}
		return v;
	}

}
